package com.ruoyi.config;




import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.domain.T06;
import com.ruoyi.domain.T22;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.service.IT06Service;
import com.ruoyi.service.IT22Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpRequest;
import org.springframework.util.ObjectUtils;


import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Configuration
public class SensitiveWordConfig {

    // 自定义敏感词来源（从数据库读取）
    @Bean
    public IWordDeny wordDeny(HttpServletRequest request) {
        return () -> {
            T22 sensitiveWordLib=new T22();
//            sensitiveWordLib.setDelFlag("0");
//            List<T22> sensitiveWordLibs=t22Service.selectT22List(sensitiveWordLib);
//           List<String> list= sensitiveWordLibs.stream().map(s->s.getWord()).collect(Collectors.toList());


                return new ArrayList<String>();
        };
    }

    // 初始化敏感词工具
    @Bean
    public SensitiveWordBs sensitiveWordBs(IWordDeny wordDeny) {
        return SensitiveWordBs.newInstance()
                .wordDeny(wordDeny)       // 设置敏感词库
                .ignoreCase(true)           // 忽略大小写
//                .replace((word, context) -> "*".replace(word.length())) // 替换为*
                .init();                    // 初始化
    }


}
